<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
	</head>

	<body>

		<header class="mui-bar mui-bar-nav own-main-background-color">
			<h1 id="title" class="mui-title">推荐</h1>
		</header>

		<!--
				作者：460575807@qq.com
				时间：2017-07-12
				描述：底部选项卡
			-->
		<nav class="mui-bar mui-bar-tab">
			<a class="mui-tab-item mui-active" href="tab_tuijian.html">
				<span class="mui-icon mui-icon-star"></span>
				<span class="mui-tab-label">推荐</span>
			</a>
			<a class="mui-tab-item" href="tab_fenlei.html">
				<span class="mui-icon mui-icon-bars"><span class="mui-badge">9</span></span>
				<span class="mui-tab-label">分类</span>
			</a>
			<a class="mui-tab-item" href="tab_faxian.html">
				<span class="mui-icon mui-icon-search"></span>
				<span class="mui-tab-label">发现</span>
			</a>
			<a class="mui-tab-item" href="tab_gouwuche.html">
				<span class="mui-icon mui-icon-flag"></span>
				<span class="mui-tab-label">购物车</span>
			</a>
			<a class="mui-tab-item" href="tab_wode.html">
				<span class="mui-icon mui-icon-person"></span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>

		<script src="../js/mui.min.js"></script>
		<script type="text/javascript">
			mui.init();

			var subpages = ['tab_tuijian.html', 'tab_fenlei.html', 'tab_faxian.html', 'tab_gouwuche.html', 'tab_wode.html'];
			var subpage_style = {
				top: '45px',
				bottom: '51px'
			};

			var aniShow = {};

			//创建子页面，首个选项卡页面显示，其它均隐藏；
			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				for(var i = 0; i <= 4; i++) {
					var temp = {};
					var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
					if(i > 0) {
						sub.hide();
					} else {
						temp[subpages[i]] = "true";
						mui.extend(aniShow, temp);
					}
					self.append(sub);
				}
			});
			//当前激活选项
			var activeTab = subpages[0];
			var title = document.getElementById("title");
			//选项卡点击事件
			mui('.mui-bar-tab').on('tap', 'a', function(e) {
				var targetTab = this.getAttribute('href');
				if(targetTab == activeTab) {
					return;
				}
				//更换标题
				title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
				//显示目标选项卡
				//若为iOS平台或非首次显示，则直接显示
				if(mui.os.ios || aniShow[targetTab]) {
					plus.webview.show(targetTab);
				} else {
					//否则，使用fade-in动画，且保存变量
					var temp = {};
					temp[targetTab] = "true";
					mui.extend(aniShow, temp);
					plus.webview.show(targetTab, "fade-in", 300);
				}
				//隐藏当前;
				plus.webview.hide(activeTab);
				//更改当前活跃的选项卡
				activeTab = targetTab;
			});
		</script>
	</body>

</html>